package com.example.blog.mapper;

import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import lombok.NonNull;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogMapper {
    //返回博客列表
    @Select("select * from blog_info where delete_flag = 0")
    List<BlogInfo> selectAll();
    //根据Id返回博客信息
    @Select("select * from blog_info where id = #{id}")
    BlogInfo selectById(Integer id);
    //更新博客
    Integer updateBlog(BlogInfo blogInfo);
    //发布博客
    @Insert("insert into blog_info (title,content,user_id) values (#{title},#{content},#{userId}) ")
    Integer insertBlog(BlogInfo blogInfo);
    //获取博客详情
    @Select("select * from blog_info where id = #{id}")
    BlogInfo getBlogDetail(Integer id);

    //删除博客
    @Update("update blog_info set delete_flag = 1 where id = #{blogId}")
    Integer deleteBlogById(@NonNull Integer blogId);
}
